import java.util.Arrays;

public class Company {
    String name;
    String site;
    String telephone;
    String scope;
    Staff[] staff = new Staff[100];
    int count = 0;

    public Company() {
        this.name = "北";
        this.site = "北京";
        this.telephone = "00000";
        this.scope = "北京";
    }

    public void show() {
        System.out.println("公司：" + name + "\t注册地址：" + site + "\t电话：" + telephone + "\t经营范围：" + scope);
    }

    public void recruit(String name, int age, String gende, String duty, double money) {
        if (count >= staff.length) {
            System.out.println("公司已满");
            return;
        }
        for (int i = 0; i < count; i++) {
            if (staff[i].name.equals(name)) {
                System.out.println("员工重复");
                return;
            }
        }

        staff[count] = new Staff();
        staff[count].name = name;
        staff[count].age = age;
        staff[count].gende = gende;
        staff[count].duty = duty;
        staff[count].money = money;
        count++;
        System.out.println("添加成功");
    }

    public void message() {
        for (int i = 0; i < count; i++) {
            System.out.println("员工姓名：" + staff[i].name + "\t年龄" + staff[i].age + "\t性别" + staff[i].gende + "\t职务" + staff[i].duty + "\t薪水" + staff[i].money);
        }
    }

    public int people() {
        return count;
    }

    public void refuse(String name) {
        for (int i = 0; i < count; i++) {
            if (staff[i].name.equals(name)) {
                int j = i;
                for (; j < count - 1; j++) {
                    staff[j].name = staff[j + 1].name;
                    staff[j].age = staff[j + 1].age;
                    staff[j].gende = staff[j + 1].gende;
                    staff[j].duty = staff[j + 1].duty;
                    staff[j].money = staff[j + 1].money;
                }
                staff[j] = null;
                count--;
                System.out.println("辞退成功");
                return;
            }
        }
        System.out.println("公司没有此员工");
    }

    //    public String findTopSalary(){
//        if(count==0)
//            return null;
//        double max=staff[0].money;
//        int i=0;
//        for(;i<count-1;i++){
//            if(staff[i].money<staff[i+1].money){
//                max=staff[i+1].money;
//            }
//        }
//        return staff[i].name;
//    }
    public void findTopSalary() {
        if (count == 0)
            return;
        double max = staff[0].money;
        int i = 0;
        for (; i < count - 1; i++) {
            if (staff[i].money < staff[i + 1].money) {
                max = staff[i + 1].money;
            }
        }
        for (int j = 0; j < count; j++) {
            if (max == staff[j].money) {
                System.out.println(staff[j].name);
            }
        }


    }

    public void sortBySalDesc() {
        if (count == 0)
            return;
        double[] d = new double[count];
        for (int i = 0; i < count; i++) {
            d[i] = staff[i].money;
        }
        double sb=0;
        for (int i = 0; i < count - 1; i++) {
            for (int j = 0; j< count-1-i; j++){
                if(d[j]<d[j+1]){
                    sb=d[j];
                    d[j]=d[j+1];
                    d[j+1]=sb;
                }
            }
        }
        System.out.println(Arrays.toString(d));
    }
    public double average(){
        if (count == 0)
            return 0;
        double sum=0;
        for(int i=0;i<count;i++){
            sum=sum+staff[i].money;
        }
        double avg=sum/count;
        return avg;
    }
    public void addmoney(){
        if (count == 0)
            return;
        for(int i=0;i<count;i++){
            if(staff[i].money<5000){
                staff[i].money=500+staff[i].money;
                continue;
            }
            staff[i].money=staff[i].money+100;
        }
        System.out.println("增加成功");

    }


}
